/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller;

import java.util.ArrayList;

/**
 *
 * @author Monkey
 */
public class CartList {

    ArrayList<CartBean> list = null;

    public CartList() {
        list = new ArrayList<CartBean>();
    }

    public void addBook(CartBean cart) {
        boolean found = false;
        int cartQuantity = cart.getQuantity();
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getBookID().equals(cart.getBookID())) {
                found = true;
                int currentQuantity = list.get(i).getQuantity();
                list.get(i).setQuantity(cartQuantity + currentQuantity);
                return;
            }
        }
        if (found == false) {
            list.add(cart);
        }
    }

    public void remove(String id) {
        if (list != null) {
            for (int i = 0; i <= list.size(); i++) {
                if (list.get(i).getBookID().equals(id)) {
                    list.remove(i);
                    return;
                }
            }
        }
    }

    public ArrayList<CartBean> getList() {
        return list;
    }
}
